import os
import time
import unittest
from page.admin_index_page import IndexPage
from common.base import get_driver
from selenium.webdriver.common.by import By


class ViewOrderCase(unittest.TestCase):
    @classmethod
    def setUpClass(cls) -> None:
        # 类夹具定义登录
        driver = get_driver()
        driver.get('http://localhost:8080/ecshop/admin/index.php')
        cls.test = IndexPage(driver)
        cls.test.click((By.XPATH, '//span[@onclick]'))
        cls.test.click((By.ID, 'cloudLogin'))
        cls.test.send_keys((By.NAME, 'username'), 'root1234')
        cls.test.send_keys((By.NAME, 'password'), 'root1234')
        cls.test.click((By.XPATH, '//input[@type="submit"]'))
        time.sleep(2)

    def test_view_order(self):
        # TODO 创建订单
        self.test.to_left_menu()
        self.test.to_add_order()
        self.test.to_main_menu()
        self.test.next_step()
        self.test.search_goods_number("70")
        self.test.add_to_order()
        self.test.next_step()
        self.test.order_consignee("yun")
        self.test.choice_addr()
        self.test.input_email("12.@123.com")
        self.test.input_addr("成都高新")
        self.test.input_tel("12312342234")
        self.test.next_step()
        self.test.choice_courier()
        self.test.next_step()
        self.test.choice_pay()
        self.test.next_step()
        self.test.next_step()
        self.test.finish_order()
        # TODO 查看订单 获取实际订单号和预期订单号
        order_number = self.test.get_order_number()
        self.test.choice_parent_frame()
        self.test.to_left_menu()
        self.test.to_order_list()
        self.test.to_main_menu()
        real_order_number = self.test.get_real_order_number()

        # TODO 断言
        """
        预期 和 实际结果 的比对
        """
        # 定位预期结果
        time.sleep(6)
        self.assertEqual(order_number, real_order_number, msg="订单添加失败")
        # 完成退出浏览器
        self.test.quit()


if __name__ == '__main__':
    unittest.main(verbosity=2)
